/*
 * @Author: your name
 * @Date: 2021-05-19 17:22:23
 * @LastEditTime: 2021-05-30 18:15:24
 * @LastEditors: Please set LastEditors
 * @Description: In User Settings Edit
 * @FilePath: /xiangpan-admin/src/pages/home/scheduModal/index.tsx
 */
import { IFormTypeEnum } from '@/components/form/formComponent';
import { FormInstance, Modal } from 'antd';
import HeaderForm from '@/components/form';

import React, { useEffect } from 'react';
import { SEX } from '@/enum';
import { add_staff, edit_staff } from '@/services/pages';
import { IForm } from '../../../components/form/interface';
import { globalModel } from '../../globalModel';
interface IProps {
  visible: boolean;
  close: () => void;
  refresh: () => void;
  row?: any;
}

const StaffModal = (props: IProps) => {
  const List: IForm[] = [
    {
      key: 'staff_name',
      type: IFormTypeEnum.Input,
      label: '姓名',
      rules: [{ required: true }],
    },
    {
      key: 'sex',
      type: IFormTypeEnum.RadioGroup,
      label: '性别',
      rules: [{ required: true }],
      data: { list: SEX },
    },
    // {
    //   key: 'mobile',
    //   type: IFormTypeEnum.InputNumber,
    //   label: '手机号',
    //   rules: [{ required: true }],
    //   data: { list: SEX },
    // },
    {
      key: 'account',
      type: IFormTypeEnum.Input,
      label: '账号',
      rules: [{ required: true }],
    },
    {
      key: 'password',
      type: IFormTypeEnum.Input,
      label: '密码',
      rules: [{ required: true }],
    },
    {
      key: 'weight',
      type: IFormTypeEnum.Slider,
      label: '权重',
      rules: [{ required: true }],
    },
  ];

  const onFinish = async (values: any, form: FormInstance) => {
    if (props.row?.staff_id) {
      await edit_staff({ ...values, staff_id: props.row?.staff_id });
    } else {
      await add_staff(values);
    }
    props.close();
    props.refresh();
  };

  useEffect(() => {}, []);

  return (
    <Modal
      maskClosable={false}
      visible={props.visible}
      title={props.row?.staff_id ? '编辑技师' : '添加技师'}
      footer={null}
      onCancel={props.close}
    >
      <HeaderForm
        labelwidth={80}
        layout="horizontal"
        list={List}
        onSubmit={onFinish}
        initialValues={props.row}
      />
    </Modal>
  );
};
export default StaffModal;
